feat(ISearchFormItemMetadata): add RenderContent method#7785
feat(ISearchFormItemMetadata): add RenderContent method#7785
Conversation
Reviewer's GuideAdds a customizable RenderContent hook to ISearchFormItemMetadata and its base class, updates SearchForm and Table search form generation to use it and a shared localizer helper, and introduces a unit test demonstrating custom metadata rendering. Sequence diagram for custom search item rendering with RenderContentsequenceDiagram
actor User
participant SearchForm
participant ISearchItem
participant Metadata as ISearchFormItemMetadata
User->>SearchForm: OpenSearchForm()
SearchForm->>ISearchItem: AutoGenerateTemplate(item)
ISearchItem-->>SearchForm: item with Metadata
SearchForm->>Metadata: RenderContent()
alt custom content provided
Metadata-->>SearchForm: RenderFragment customContent
SearchForm-->>User: Render customContent
else no custom content
Metadata-->>SearchForm: null
SearchForm->>ISearchItem: CreateSearchItemComponentByMetadata()
ISearchItem-->>SearchForm: RenderFragment defaultContent
SearchForm-->>User: Render defaultContent
end
User->>SearchForm: Change search value
SearchForm->>SearchForm: Items.ToFilter()
SearchForm->>SearchForm: OnChanged(filter)
Class diagram for updated search form item metadata hierarchyclassDiagram
class ISearchFormItemMetadata {
+Reset()
+RenderContent() RenderFragment?
}
class SearchFormItemMetadataBase {
+Reset()
+RenderContent() RenderFragment?
}
class DateTimeSearchMetadata
class DateTimeRangeSearchMetadata
class NumberSearchMetadata
class StringSearchMetadata
class SelectSearchMetadata
class MultipleSelectSearchMetadata {
+GetFilter(fieldName string) FilterKeyValueAction?
}
ISearchFormItemMetadata <|.. SearchFormItemMetadataBase
SearchFormItemMetadataBase <|-- DateTimeSearchMetadata
SearchFormItemMetadataBase <|-- DateTimeRangeSearchMetadata
SearchFormItemMetadataBase <|-- NumberSearchMetadata
SearchFormItemMetadataBase <|-- StringSearchMetadata
SearchFormItemMetadataBase <|-- SelectSearchMetadata
SelectSearchMetadata <|-- MultipleSelectSearchMetadata
Flow diagram for shared SearchFormLocalizerOptions creationflowchart TD
subgraph Components
SearchForm
Table
end
IStringLocalizer_SearchFormLocalizerOptions
SearchFormLocalizerOptions
SearchForm -->|needs options| SearchFormLocalizerOptions
Table -->|needs options| SearchFormLocalizerOptions
SearchFormLocalizerOptions -->|if null| IStringLocalizer_SearchFormLocalizerOptions
IStringLocalizer_SearchFormLocalizerOptions -->|GetSearchFormLocalizerOptions| SearchFormLocalizerOptions
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
SearchForm.AutoGenerateTemplate, callingitem.Metadata.RenderContent()without a null check can introduce a new null reference path for items without metadata; consider using a null-conditional access or defaulting toCreateSearchItemComponentByMetadata()whenMetadatais null. - The test helper class name
CustomeMetadataappears to be a typo; renaming it toCustomMetadatawould improve clarity and avoid confusion for future readers.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `SearchForm.AutoGenerateTemplate`, calling `item.Metadata.RenderContent()` without a null check can introduce a new null reference path for items without metadata; consider using a null-conditional access or defaulting to `CreateSearchItemComponentByMetadata()` when `Metadata` is null.
- The test helper class name `CustomeMetadata` appears to be a typo; renaming it to `CustomMetadata` would improve clarity and avoid confusion for future readers.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Pull request overview
Adds a customization hook to SearchForm search-item metadata so consumers can provide their own UI rendering, while refactoring localizer option construction into a shared helper.
Changes:
- Added
RenderContent()toISearchFormItemMetadataand integrated it intoSearchFormrendering (fallback to existing metadata-based rendering). - Renamed
SearchMetadataBasetoSearchFormItemMetadataBaseand updated built-in metadata types to inherit the new base. - Extracted
SearchFormLocalizerOptionsconstruction into anIStringLocalizerextension and reused it inSearchFormandTable.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTest/Components/SearchFormTest.cs | Adds a unit test verifying custom metadata can render custom search UI. |
| src/BootstrapBlazor/Extensions/IStringLocalizerExtensions.cs | Introduces a helper to build SearchFormLocalizerOptions from a localizer. |
| src/BootstrapBlazor/Extensions/ISearchItemExtensions.cs | Updates XML doc wording for metadata-based rendering helper. |
| src/BootstrapBlazor/Components/Table/Table.razor.Search.cs | Refactors localizer options initialization to use the new extension method. |
| src/BootstrapBlazor/Components/Searches/StringSearchMetadata.cs | Updates inheritance to the renamed metadata base class. |
| src/BootstrapBlazor/Components/Searches/SearchFormItemMetadataBase.cs | Renames base class and adds a virtual RenderContent() default implementation. |
| src/BootstrapBlazor/Components/Searches/NumberSearchMetadata.cs | Updates inheritance to the renamed metadata base class. |
| src/BootstrapBlazor/Components/Searches/MultipleSelectSearchMetadata.cs | Updates inheritdoc reference to the renamed base class. |
| src/BootstrapBlazor/Components/Searches/ISearchFormItemMetadata.cs | Adds the new RenderContent() API to metadata. |
| src/BootstrapBlazor/Components/Searches/DateTimeSearchMetadata.cs | Updates inheritance to the renamed metadata base class. |
| src/BootstrapBlazor/Components/Searches/DateTimeRangeSearchMetadata.cs | Updates inheritance to the renamed metadata base class. |
| src/BootstrapBlazor/Components/SearchForm/SearchForm.razor.cs | Uses Metadata.RenderContent() when provided; refactors localizer options creation. |
| src/BootstrapBlazor.Server/Locales/zh-CN.json | Reorders SearchFormTips entry (no value change). |
Comments suppressed due to low confidence (1)
src/BootstrapBlazor/Components/Searches/SearchFormItemMetadataBase.cs:15
- Renaming the public base type from
SearchMetadataBasetoSearchFormItemMetadataBaseis a breaking change for consumers deriving fromSearchMetadataBase. To preserve backward compatibility, consider keeping aSearchMetadataBasetype as an[Obsolete]shim that inherits fromSearchFormItemMetadataBase(at least for one major/minor release).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7785 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 764 764
Lines 34115 34109 -6
Branches 4696 4697 +1
=========================================
- Hits 34115 34109 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #7784
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Add support for custom-rendered search form items via metadata and centralize search form localization options retrieval.
New Features:
Enhancements:
Tests: